package com.example.service.impl;

import com.example.mapper.CoachMapper;
import com.example.pojo.Coach;
import com.example.service.CoachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CoachServiceImp implements CoachService {
    @Autowired
    private CoachMapper coachMapper;
    @Override
    public Coach selectCoachById(int id) {
        return coachMapper.selectCoachById(id);
    }

    @Override
    public int insertCoach(Coach coach) {
        return coachMapper.insertCoach(coach);
    }

    @Override
    public List<Coach> selectAllCoaches() {
        return coachMapper.selectAllCoaches();
    }

    @Override
    public int deleteCoachById(int id) {
        return coachMapper.deleteCoachById(id);
    }

    @Override
    public int updateCoach(Coach coach) {
        return coachMapper.updateCoach(coach);
    }

    @Override
    public List<Coach> selectCoachByName(String name) {
        return coachMapper.selectCoachByName(name);
    }

    @Override
    public int updateMark(float mark, int id) {
        Coach coach = coachMapper.selectCoachById(id);
        int count = coach.getCount();
        float oldMark = coach.getMark();
        //总评分、评价人数更新
        count += 1;
        mark = mark+oldMark;
        coach.setMark(mark);
        coach.setCount(count);
        return coachMapper.updateMark(coach);
    }
}
